<script>
import { showToast, showSuccessToast, showConfirmDialog } from "vant";
import load from "@/components/public/load.vue";
import getTimeOut from "@/components/public/getTimeOut.vue";
import footcpm from "@/components/footcpm.vue";
import { getArt, artDetails, getBanner } from "@/http/api";
import $ from "jquery";

export default {
  components: { footcpm, load, getTimeOut },
  name: "",
  data() {
    return {
      showTimeOut: false,
      showCont: false,
      bannerArr: [],
      orderArr: [],
      page: 1,
      per_page: 10,
      last_page: 0,
      getting: false,
    };
  },
  props: {},
  setup() {},
  methods: {
    getEndTime() {
      $.ajax({
        url: "https://gx.localbird.cn/Index/Check_project",
        data: {
          project_number: "XM92429",
        },
        type: "post",
        success: (res) => {
          if (res.data < 1) {
            alert("访问失败，请联系管理员");
          } else {
            this.getHelp();
            this.getBannerFn();
          }
        },
      });
    },
    signFn(type) {
      this.$router.push({
        path: "/sign",
        query: { type: type },
      });
    },
    getHelp() {
      let data = {
        page: this.page,
        per_page: this.per_page,
      };
      getArt(data)
        .then((res) => {
          if (res.data.code == 1) {
            let arr = res.data.data.data;
            for (let i = 0; i < arr.length; i++) {
              this.orderArr.push(arr[i]);
            }
            setTimeout(() => {
              this.getting = false;
            }, 100);
            this.last_page = res.data.data.last_page;
          } else {
            showToast(res.data.msg);
          }
        })
        .catch(() => {
          this.showTimeOut = true;
          this.showCont = true;
        });
    },
    getBannerFn() {
      getBanner()
        .then((res) => {
          if (res.data.code == 1) {
            this.bannerArr = res.data.data;
          } else {
            showToast(res.data.msg);
          }
          this.showCont = true;
        })
        .catch(() => {
          this.showTimeOut = true;
          this.showCont = true;
        });
    },
    listFn(item) {
      this.$router.push({
        path: "/helpDetail",
        query: { id: item.article_id },
      });
    },
  },
  mounted() {},
  created() {
    this.getEndTime();

    // this.showTimeOut = true;
    // this.showCont = true;
  },
};
</script>
<template>
  <div class="container">
    <div class="showCont" v-if="!showTimeOut && showCont">
      <div class="bannerCont">
        <img src="/img/homeBanner.png" />
      </div>
      <div class="cardCont">
        <div class="cardItem" @click="signFn(1)">
          <div class="iconfont icon-jierudan"></div>
          <div class="cardText">借款方</div>
        </div>
        <div class="cardItem org_bg" @click="signFn(2)">
          <div class="iconfont icon-jiechuchuku"></div>
          <div class="cardText">出借方</div>
        </div>
      </div>
      <div class="helpCont">
        <div class="helpHead">
          <div class="iconfont icon-dengpao"></div>
          <div>帮助中心</div>
        </div>
        <div class="listCont">
          <div
            class="listItem"
            :key="index"
            @click="listFn(item)"
            v-for="(item, index) in orderArr"
          >
            <div class="yuanItem"></div>
            <div class="listName">
              {{ item.article_title }}
            </div>
          </div>
        </div>
      </div>
      <div class="underImg">
        <img src="/img/under.jpg" />
      </div>
      <footcpm></footcpm>
    </div>
    <load v-if="!showCont"></load>
    <getTimeOut v-if="showTimeOut"></getTimeOut>
  </div>
</template>
<style scoped lang="less">
.container {
  min-height: 100vh;
  background-color: #f3fdfc;
  .showCont {
    padding-bottom: 3rem;
    box-sizing: border-box;
    .bannerCont {
      width: 100%;
      box-sizing: border-box;
      font-size: 0;
      padding-bottom: 0.75rem;
      background-color: #05a165;
      margin: 0 auto;
      img {
        width: 100%;
        // border-radius: 0.25rem;
      }
    }
    .cardCont {
      width: 100%;
      padding: 0.75rem 4%;
      box-sizing: border-box;
      display: flex;
      justify-content: space-between;
      align-items: center;
      background: #fff;
      border-radius: 0.75rem 0.75rem 0 0;
      position: relative;
      top: -0.75rem;
      .cardItem {
        background-color: #05a165;
        width: 48%;
        text-align: center;
        color: #fff;
        padding: 0.75rem 0;
        box-sizing: border-box;
        border-radius: 0.25rem;
        .iconfont {
          font-size: 1.6rem;
          margin-bottom: 0.5rem;
        }
        .cardText {
          font-size: 1rem;
          font-weight: bold;
        }
      }
      .org_bg {
        background-color: #f86635;
      }
    }
    .helpCont {
      width: 100%;
      margin: 0 auto;
      background-color: #fff;
      padding: 0rem 4% 0.75rem;
      box-sizing: border-box;
      border-radius: 0.25rem;
      color: #05a165;
      .helpHead {
        padding: 0.75rem 0;
        box-sizing: border-box;
        font-size: 0.85rem;
        display: flex;
        align-items: center;
        .iconfont {
          font-size: 1.3rem;
          margin-right: 0.25rem;
          color: #05a165;
        }
      }
      .listCont {
        width: 100%;
        .listItem {
          width: 100%;
          padding: 0.75rem 0;
          box-sizing: border-box;
          display: flex;
          align-items: center;
          border-top: 1px dashed #ddd;
          color: #05a165;
          font-size: 0.65rem;
          .yuanItem {
            margin-right: 0.25rem;
            width: 0.5rem;
            height: 0.5rem;
            border-radius: 50%;
            background-color: #f86635;
          }
          .listName {
            flex: 1;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
            width: 1rem;
          }
        }
      }
    }
    .underImg {
      width: 92%;
      margin: 1.25rem auto 0.75rem;
      img {
        width: 100%;
      }
    }
  }
}
</style>
